1 задача¶

  1. Скачать данные по ссылке https://drive.google.com/file/d/1MpAdHAl727fO3oW32NO4FpSRhUBUfjfS
  2. Считать данные с помощью pandas
  3. Вывести на экран первые 5 строк
In [72]:
import pandas as pd

df = pd.read_csv('laptops_10.csv')
df.head()
Out[72]:
Company Product TypeName Inches Cpu Ram Gpu OpSys Weight Price_euros Cpu_Company Memory_Amount Memory_Type
0 Apple MacBook Pro Ultrabook 13.3 Intel Core i5 2.3GHz 8GB Intel Iris Plus Graphics 640 macOS 1.37 1339.69 Intel 128 SSD
1 Apple Macbook Air Ultrabook 13.3 Intel Core i5 1.8GHz 8GB Intel HD Graphics 6000 macOS 1.34 898.94 Intel 128 FlashStorage
2 HP 250 G6 Notebook 15.6 Intel Core i5 7200U 2.5GHz 8GB Intel HD Graphics 620 No OS 1.86 575.00 Intel 256 SSD
3 Apple MacBook Pro Ultrabook 15.4 Intel Core i7 2.7GHz 16GB AMD Radeon Pro 455 macOS 1.83 2537.45 Intel 512 SSD
4 Apple MacBook Pro Ultrabook 13.3 Intel Core i5 3.1GHz 8GB Intel Iris Plus Graphics 650 macOS 1.37 1803.60 Intel 256 SSD

1.1 Изучите количество памяти с помощью matplotlib¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [73]:
import matplotlib.pyplot as plt

#plt.figure(figsize =(15,5))
plt.hist(df['Memory_Amount'], bins=30)
plt.title('Распределение памяти')
plt.xlabel('GB')
plt.ylabel('Количество');
No description has been provided for this image

1.2 Изучите стоимость ноутбуков с помощью matplotlib¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [74]:
plt.figure(figsize =(15,5))
plt.hist(df['Price_euros'], color = 'red', edgecolor='black', bins=30)
plt.title('Распределение стоимости')
plt.xlabel('euro')
plt.ylabel('Количество');
No description has been provided for this image

1.3 Изучите вес ноутбуков с помощью matplotlib¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [75]:
plt.hist(df['Weight'])
plt.title('Распределение веса')
plt.xlabel('kg')
plt.ylabel('Количество');
No description has been provided for this image

2 Задача¶

2.1 Изучите распределение типов носителя¶

  • Постройте график
  • Сделайте выводы
In [76]:
data = df['Memory_Type'].value_counts()
data
Out[76]:
Memory_Type
SSD             641
HDD             576
FlashStorage     74
Hybrid           12
Name: count, dtype: int64
In [77]:
names = data.index
values = data.values
In [78]:
plt.pie(values, autopct='%.1f%%', labels=names);
No description has been provided for this image

2.2 Изучите распределение компаний производителей¶

  • Постройте график
  • Сделайте выводы
In [79]:
data = df['Company'].value_counts()
data
Out[79]:
Company
Dell         297
Lenovo       297
HP           274
Asus         158
Acer         103
MSI           54
Toshiba       48
Apple         21
Samsung        9
Razer          7
Mediacom       7
Microsoft      6
Xiaomi         4
Vero           4
Chuwi          3
Google         3
Fujitsu        3
LG             3
Huawei         2
Name: count, dtype: int64
In [80]:
names = data.index
values = data.values
In [81]:
plt.figure(figsize=(8, 6))
plt.bar(names, values)
plt.xticks(rotation=50);
No description has been provided for this image

2.3 Изучите распределение операционной системы¶

  • Постройте график
  • Сделайте выводы
In [82]:
data = df['OpSys'].value_counts()
data
Out[82]:
OpSys
Windows 10      1072
No OS             66
Linux             62
Windows 7         45
Chrome OS         27
macOS             13
Mac OS X           8
Windows 10 S       8
Android            2
Name: count, dtype: int64
In [83]:
names = data.index
values = data.values
In [84]:
plt.figure(figsize=(8, 6))
plt.bar(names, values)
plt.xticks(rotation=50);
No description has been provided for this image

2.4 Изучите распределение компаний производителей CPU¶

  • Постройте график
  • Сделайте выводы
In [85]:
data = df['Cpu_Company'].value_counts()
data
Out[85]:
Cpu_Company
Intel      1240
AMD          62
Samsung       1
Name: count, dtype: int64
In [86]:
names = data.index
values = data.values
In [87]:
plt.pie(values, autopct='%.1f%%', labels=names, wedgeprops=dict(width=0.25));
No description has been provided for this image

3 задача¶

Изучите взаимосвязь компаний производителей ноутбуков и компаний производителей процессоров, используя сложенную или многорядовую столбчатую диаграмму

Процессоры от Samsung не изучайте

3.1 Постройте график в абсолютных величинах¶

In [88]:
data = pd.crosstab(index=df['Company'], columns=df['Cpu_Company'])
data = data.drop(columns=['Samsung']).reset_index()
data
Out[88]:
Cpu_Company Company AMD Intel
0 Acer 10 93
1 Apple 0 21
2 Asus 11 147
3 Chuwi 0 3
4 Dell 0 297
5 Fujitsu 0 3
6 Google 0 3
7 HP 25 249
8 Huawei 0 2
9 LG 0 3
10 Lenovo 16 281
11 MSI 0 54
12 Mediacom 0 7
13 Microsoft 0 6
14 Razer 0 7
15 Samsung 0 8
16 Toshiba 0 48
17 Vero 0 4
18 Xiaomi 0 4
In [89]:
import numpy as np

plt.figure(figsize=(14, 6))
n_ticks = np.arange(len(data['AMD']))
offset = 0.2
w = 0.4

plt.bar(n_ticks - offset, data['AMD'], width=w)
plt.bar(n_ticks + offset, data['Intel'], width=w)

plt.title('Ноутбуки')
plt.xlabel('Компания производитель ноутбуков')
plt.ylabel('Количество ноутбуков')
plt.legend(['AMD', 'Intel'])
plt.xticks(n_ticks, data['Company'], rotation=50); 
No description has been provided for this image

3.2 Постройте график в относительных величинах¶

In [90]:
data = pd.crosstab(index=df['Company'], columns=df['Cpu_Company'], normalize='index')
data = data.drop(columns=['Samsung']).reset_index()
data
Out[90]:
Cpu_Company Company AMD Intel
0 Acer 0.097087 0.902913
1 Apple 0.000000 1.000000
2 Asus 0.069620 0.930380
3 Chuwi 0.000000 1.000000
4 Dell 0.000000 1.000000
5 Fujitsu 0.000000 1.000000
6 Google 0.000000 1.000000
7 HP 0.091241 0.908759
8 Huawei 0.000000 1.000000
9 LG 0.000000 1.000000
10 Lenovo 0.053872 0.946128
11 MSI 0.000000 1.000000
12 Mediacom 0.000000 1.000000
13 Microsoft 0.000000 1.000000
14 Razer 0.000000 1.000000
15 Samsung 0.000000 0.888889
16 Toshiba 0.000000 1.000000
17 Vero 0.000000 1.000000
18 Xiaomi 0.000000 1.000000
In [91]:
plt.figure(figsize=(8, 6))

plt.bar(data['Company'], data['AMD'])
plt.bar(data['Company'], data['Intel'], bottom=data['AMD'])

plt.title('Ноутбуки')
plt.xlabel('Компания производитель ноутбуков')
plt.ylabel('Доля ноутбуков')
plt.legend(['AMD', 'Intel'])
plt.xticks(rotation=50);
No description has been provided for this image

4 задача¶

4.1 Изучите взаимосвязь стоимости ноутбука и компании производителя процессора¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [92]:
import seaborn as sns

plt.figure(figsize=(10, 6))

sns.boxplot(x=df['Price_euros'], y=df['Cpu_Company'], whis=1.5, showfliers=False)

plt.xlabel('Price_euros')
plt.ylabel('Cpu_Company')
plt.title('Distribution of Price_euros by Cpu_Company');
No description has been provided for this image

4.2 Изучите взаимосвязь стоимости ноутбука и типа носителя памяти¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [93]:
plt.figure(figsize=(10, 6))

sns.boxplot(x=df['Price_euros'], y=df['Memory_Type'], whis=1.5, showfliers=False)
#sns.set(context='notebook', style='darkgrid', palette='deep', font='sans-serif', font_scale=1, color_codes=False, rc=None)
plt.xlabel('Price_euros')
plt.ylabel('Memory_Type')
plt.title('Distribution of Price_euros by Memory_Type');
No description has been provided for this image

4.3 Изучите взаимосвязь стоимости ноутбука и кол-ва оперативной памяти¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [94]:
plt.figure(figsize=(10, 6))

sns.boxplot(x=df['Price_euros'], y=df['Ram'], whis=1.5, showfliers=False)

plt.xlabel('Price_euros')
plt.ylabel('Ram')
plt.title('Distribution of Price_euros by Ram');
No description has been provided for this image

4.4 Изучите взаимосвязь стоимости ноутбука и компании производителя¶

  • Постройте график
  • Назовите график
  • Сделайте именование оси x и оси y
  • Сделайте выводы
In [95]:
plt.figure(figsize=(10, 6))

sns.boxplot(x=df['Price_euros'], y=df['Company'], whis=1.5, showfliers=False)

plt.xlabel('Price_euros')
plt.ylabel('Company')
plt.title('Distribution of Price_euros by Company');
No description has been provided for this image

5 задача*¶

Постройте матрицу корреляций для таблицы

In [ ]:
 
In [96]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1303 entries, 0 to 1302
Data columns (total 13 columns):
 #   Column         Non-Null Count  Dtype  
---  ------         --------------  -----  
 0   Company        1303 non-null   object 
 1   Product        1303 non-null   object 
 2   TypeName       1303 non-null   object 
 3   Inches         1303 non-null   float64
 4   Cpu            1303 non-null   object 
 5   Ram            1303 non-null   object 
 6   Gpu            1303 non-null   object 
 7   OpSys          1303 non-null   object 
 8   Weight         1303 non-null   float64
 9   Price_euros    1303 non-null   float64
 10  Cpu_Company    1303 non-null   object 
 11  Memory_Amount  1303 non-null   int64  
 12  Memory_Type    1303 non-null   object 
dtypes: float64(3), int64(1), object(9)
memory usage: 132.5+ KB
In [97]:
corr_matrix = df[['Inches','Weight','Price_euros','Memory_Amount']].corr()
#corr_matrix = df.corr()
corr_matrix = np.round(corr_matrix, 1)
corr_matrix[np.abs(corr_matrix) < 0.3] = 0
corr_matrix
Out[97]:
Inches Weight Price_euros Memory_Amount
Inches 1.0 0.8 0.0 0.3
Weight 0.8 1.0 0.0 0.0
Price_euros 0.0 0.0 1.0 0.0
Memory_Amount 0.3 0.0 0.0 1.0
In [98]:
plt.figure(figsize=(6, 4))
sns.heatmap(corr_matrix, annot=True, linewidths=.5, cmap='coolwarm');
No description has been provided for this image
In [102]:
import folium
df=pd.read_csv('kc_house_data.csv', sep =',')
this_map = folium.Map(prefer_canvas=True)

def plotDot(point):
    folium.CircleMarker(
        location =[point['lat'], point['long']],
        radius=2,
        popup={'price': point.price, 'floors':point.floors}).add_to(this_map)

df.apply(plotDot, axis=1)

this_map.fit_bounds(this_map.get_bounds())

this_map
Out[102]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: